# This script will create a bar graph for alpha cluster models from LDA.
# 
# Usage:
#       Rscript alphaBarPlot.R [inputfile] [outputfile]
# 
# Where inputfile is an alpha LDA model for wikipedia user clusters
# This file must be tab-separated
# 
# Where outputfile is the path for a PNG file to save the plot output.
# 
# The number of clusters is inferred by the number of columns in the model.
#
# This plot doesn't need a legend as the axes' labels are sufficient.

args <- commandArgs(TRUE)

inputfile <- args[1]
outputfile <- args[2]

model <- read.table(file=inputfile, sep="\t", quote="", comment.char="")
modelmatrix <- as.matrix(model)

clustersize <- dim(modelmatrix)[2]
ymax <- max(modelmatrix)

clusters <- as.character(c(1:clustersize))
title <- "User Distribution By Archetype"
xlabel <- "Archetype"
ylabel <- expression(paste("Parameter of Dirichlet Prior (", alpha, ")", sep=""))
ylimit <- c(0, ceiling(ymax))

png(outputfile)

barplot(modelmatrix, main=title, ylab=ylabel, xlab=xlabel, names.arg=clusters, ylim = ylimit)

dev.off()
